#include "LogFileStream.h"
#include <ctime>
#include <sstream>
#include "Vector2.h"
#include "Rect.h"
#include "Circle.h"

LogFileStream& LogFileStream::Log(int level /* = LEVEL_NOTE*/)
{
    //write time
    *this << std::endl << Now( ) << "-- ";

    //write level
    switch( level )
    {
    case LogFileStream::LEVEL_NOTE:
        *this << "NOTE: ";
        break;
    case LogFileStream::LEVEL_WARNING:
        *this << "WARNING: ";
        break;
    case LogFileStream::LEVEL_ERROR:
        *this << "ERROR: ";
        break;
    }

    //return this stream to write external values
    return *this;
}

std::string LogFileStream::Now()
{
    std::stringstream res;

    //init time
    time_t rawtime;
    time( &rawtime );

    struct tm * timeinfo;
    timeinfo = localtime( &rawtime );

    //format time and write to file
    char timeStr[50];
    strftime( timeStr, 50, "%c", timeinfo );

    res << "(" << timeStr << ") ";
    return res.str( );
}
//i could overload the << operator in order to obtain the data written to any channel written in CHANNEL_MAIN.(alla upotheto variosoun xD)

std::ostream& operator <<( std::ostream& stream, const Math::Vector2I& vector )
{
    stream << "(" << vector.GetX( ) << "," << vector.GetY( ) << ")";
    return stream;
}

std::ostream& operator <<( std::ostream& stream, const Math::Vector2F& vector )
{
    stream << "(" << vector.GetX( ) << "," << vector.GetY( ) << ")";
    return stream;
}

std::ostream& operator <<( std::ostream& stream, const Math::Vector2D& vector )
{
    stream << "(" << vector.GetX( ) << "," << vector.GetY( ) << ")";
    return stream;
}

std::ostream& operator <<( std::ostream& stream, const Math::Circle& circle )
{
    stream << "( C: " << circle.GetCenter( ) << " ,R:" << circle.GetRadious( ) << ")";
    return stream;
}

std::ostream& operator <<( std::ostream& stream, const Math::Rect& rect )
{
    stream << "( T: " << rect.GetTop( ) << ", L:" << rect.GetLeft( ) << ", H:" << rect.GetHeight( ) << ", W:" << rect.GetWidth( ) << ")";
    return stream;
}

std::ostream& operator <<( std::ostream& stream, const std::list<std::string>& list )
{
    std::list<std::string>::const_iterator it = list.begin( );
    std::list<std::string>::const_iterator end = list.end( );

    for(; it != end; ++it )
    {
        stream << ( *it ) << "\n";
    }
    return stream;

}